package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.GroupCityAddDTO;
import org.jsola.hr.dto.GroupCityUpdateDTO;
import org.jsola.hr.entity.GroupCityDO;
import org.jsola.hr.query.GroupCityQuery;
import org.jsola.hr.service.IGroupCityService;
import org.jsola.hr.vo.GroupCityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 子公司分管城市关系表
 *
 * @author zhr
 */
@Component
public class GroupCityTestHelper extends BaseTestHelper {
    
    @Autowired
    private IGroupCityService groupCityService;

    /**
     * 生成add测试数据
     * @return GroupCityAddDTO
     */
    public GroupCityAddDTO getGroupCityAddDTO(){
        GroupCityAddDTO groupCityAddDTO = new GroupCityAddDTO();
        groupCityAddDTO.setGroupId("0");
        groupCityAddDTO.setCityCode(getRandomValue("varchar",50));
        groupCityAddDTO.setCityName(getRandomValue("varchar",100));
        groupCityAddDTO.setProps(getRandomValue("text",2147483647));
        groupCityAddDTO.setIsAll(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return groupCityAddDTO;
    }


    /**
     * 生成update测试数据
     * @return GroupCityUpdateDTO
     */
    public GroupCityUpdateDTO getGroupCityUpdateDTO(GroupCityVO groupCityVO){
        return groupCityService.selectDOById(groupCityVO.getId(), SITE_ID).to(GroupCityUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return GroupCityQuery
     */
    public GroupCityQuery getGroupCityQuery() {
        GroupCityQuery groupCityQuery = new GroupCityQuery();
        List<GroupCityDO> groupCityDOList = groupCityService.list(new GroupCityDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(groupCityDOList)) {
            GroupCityDO groupCityDO = groupCityDOList.get(0);
            groupCityQuery = groupCityDO.to(GroupCityQuery.class);
        }
        return groupCityQuery;
    }

    /**
     * 保存示例
     * @return GroupCityVO
     */
    public GroupCityVO saveGroupCityExample(){
        GroupCityAddDTO addDTO = this.getGroupCityAddDTO();
        GroupCityVO groupCityVO = groupCityService.save(addDTO,buildTokenUser());
        return groupCityVO;
    }


}

